<?php

namespace App\Exceptions;

use App\Common\Tools\returnJson;
use Exception;

class ApiException extends Exception
{
    use returnJson;
    public $code;
    public $message;
    public function __construct($message, int $code = 500)
    {

        parent::__construct($message, $code);
        $this->code = $code;
        $this->message = $message;
    }

    /**
     * 报告异常
     *
     * @return void
     */
    public function report()
    {
        //
    }

    /**
     * 转换异常为 HTTP 响应
     *
     * @param  \Illuminate\Http\Request
     * @return \Illuminate\Http\Response
     */
    public function render($request)
    {
        return $this->errorReturn(['error' => $this->message],$this->code);
    }
}
